const util = require('../../utils/util');
const api = require('../../utils/api.js');

Page({
    data: {
        id: '',
        title: '',
        detail: '',
        type: '',
    },
    onLoad(options) {
        this.setData({
            id: options.id
        });
    },
    onShow() {
        this.getDetail();
    },

    getDetail() { //获取广告详情
        api.post('/ad/ad/content?adId=' + this.data.id)
            .then(res => {
                let detail = res;
                if(detail.targetType == 2) {
                    //展示公众号内容
                    this.setData({
                        title: detail.title,
                        detail: detail.content,
                        type: detail.targetType
                    })
                } else {
                    //展示详情文本
                    this.setData({
                        title: detail.title,
                        detail: util.formatRichText(detail.content),
                        type: detail.targetType
                    })
                }
            })
    },
})